--
-- VHDL Architecture Fietscomputer_lib.fc_km_teller.kmm_teller
--
-- Created:
--          by - 10070052.Demi Staal (DTP7797)
--          at - 11:55:54 29-09-2011
--
-- using Mentor Graphics HDL Designer(TM) 2008.1b (Build 7)
--
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;

ENTITY fc_km_teller IS
  PORT (
    deltat_strobe	: IN      STD_LOGIC;
    dis_const		   : IN	     STD_LOGIC_VECTOR (63 DOWNTO 0);
    clk   		      : IN      STD_LOGIC;
    rst  			      : IN      STD_LOGIC;
    start         : IN      STD_LOGIC := '0';
    km_teller	    : OUT	    STD_LOGIC_VECTOR (63 DOWNTO 0);
    ready 		      : OUT     STD_LOGIC := '0';
    div_constant  : out     std_logic_vector(63 downto 0);
    leds_out : out std_logic_vector(17 downto 0)
    );
  END fc_km_teller;
  
  --
  ARCHITECTURE kmm_teller OF fc_km_teller IS
  Signal Strobeteller : integer;
  Signal dist_const   : integer := to_integer(unsigned(dis_const));
  
  BEGIN
--    
    PROCESS(rst,clk)
      
      Begin
        IF rst = '1' THEN
          strobeteller <= 0;
          dist_const <= 0;
          ready <= '0';
          div_constant <= "0000000000000000000000000000000000000000000011110100001001000000"; -- beetje onzin om het steeds te gaan uitrekenen
          leds_out <= (others => '0');
          km_teller <= (others => '0');
        ELSIF RISING_EDGE(clk) THEN
          if dist_const = 0 then
            dist_const <= to_integer(unsigned(dis_const));
          end if;
  
          ready <= '0';
          IF deltat_strobe = '1' THEN 
            strobeteller <= strobeteller + 1;
          END IF;
          IF start = '1' and dist_const /= 0 THEN
            km_teller <= std_logic_vector(to_unsigned(strobeteller * dist_const, km_teller'length));
            ready <= '1';
          END IF;
          
          leds_out <= std_logic_vector(to_unsigned(strobeteller, leds_out'length));
          
        END IF;
      END PROCESS;
    END ARCHITECTURE kmm_teller;